<template lang="">
  <t-dialog
    :visible="props.visibles"
    width="40%"
    header="新增评分信息表"
    :confirm-loading="submitLoading"
    :destroy-on-close="true"
    @confirm="handleOnConfirm"
    @cancel="handleClose"
    @close="handleClose"
  >
    <t-form ref="form" :data="formData" :rules="rules">
      <t-form-item label="监测中心名称" name="jcName">
      <t-input v-model="formData.jcName" placeholder="请输入监测中心名称"></t-input>
    </t-form-item>
      <t-form-item label="原始记录" name="originalRecords">
      <t-input v-model="formData.originalRecords" placeholder="请输入原始记录"></t-input>
    </t-form-item>
      <t-form-item label="整编成果表" name="reorgResultScore">
      <t-input v-model="formData.reorgResultScore" placeholder="请输入整编成果表"></t-input>
    </t-form-item>
      <t-form-item label="质量控制" name="qualityControl">
      <t-input v-model="formData.qualityControl" placeholder="请输入质量控制"></t-input>
    </t-form-item>
      <t-form-item label="对外检测工作" name="externalWork">
      <t-input v-model="formData.externalWork" placeholder="请输入对外检测工作"></t-input>
    </t-form-item>
      <t-form-item label="其他记录" name="otherRecords">
      <t-input v-model="formData.otherRecords" placeholder="请输入其他记录"></t-input>
    </t-form-item>
      <t-form-item label="总分" name="totalScore">
      <t-input v-model="formData.totalScore" placeholder="请输入总分"></t-input>
    </t-form-item>
      <t-form-item label="备注" name="remark">
      <t-input v-model="formData.remark" placeholder="请输入备注"></t-input>
    </t-form-item>
      <t-form-item label="创建时间" name="createDate">
      <t-input v-model="formData.createDate" placeholder="请输入创建时间"></t-input>
    </t-form-item>
      <t-form-item label="创建人" name="createId">
      <t-input v-model="formData.createId" placeholder="请输入创建人"></t-input>
    </t-form-item>
      <t-form-item label="更新时间" name="updateDate">
      <t-input v-model="formData.updateDate" placeholder="请输入更新时间"></t-input>
    </t-form-item>
      <t-form-item label="修改人" name="updateId">
      <t-input v-model="formData.updateId" placeholder="请输入修改人"></t-input>
    </t-form-item>
      </t-form>
  </t-dialog>
</template>
<script lang="ts" setup>
import { MessagePlugin } from 'tdesign-vue-next';
import { onMounted, reactive, ref } from 'vue';

import {getList, getInfo, doDelete, doUpdate, doCreate } from '@/api/platform/waterquality/score/info';

const props = defineProps({
  visibles: {
    type: Boolean,
    default: false,
  },
});
const INITIAL_DATA = {
        jcName: '',
        originalRecords: '',
        reorgResultScore: '',
        qualityControl: '',
        externalWork: '',
        otherRecords: '',
        totalScore: '',
        remark: '',
        createDate: '',
        createId: '',
        updateDate: '',
        updateId: '',
  };
const form = ref();
const submitLoading = ref(false);
const formData: any = reactive({
  ...INITIAL_DATA,
});
const rules = reactive({
        jcName: [
      {
        required: true,
        message: '监测中心名称必填',
        type: 'error',
        trigger: 'blur',
      },],
        originalRecords: [
      {
        required: true,
        message: '原始记录必填',
        type: 'error',
        trigger: 'blur',
      },],
        reorgResultScore: [
      {
        required: true,
        message: '整编成果表必填',
        type: 'error',
        trigger: 'blur',
      },],
        qualityControl: [
      {
        required: true,
        message: '质量控制必填',
        type: 'error',
        trigger: 'blur',
      },],
        externalWork: [
      {
        required: true,
        message: '对外检测工作必填',
        type: 'error',
        trigger: 'blur',
      },],
        otherRecords: [
      {
        required: true,
        message: '其他记录必填',
        type: 'error',
        trigger: 'blur',
      },],
        totalScore: [
      {
        required: true,
        message: '总分必填',
        type: 'error',
        trigger: 'blur',
      },],
        remark: [
      {
        required: true,
        message: '备注必填',
        type: 'error',
        trigger: 'blur',
      },],
        createDate: [
      {
        required: true,
        message: '创建时间必填',
        type: 'error',
        trigger: 'blur',
      },],
        createId: [
      {
        required: true,
        message: '创建人必填',
        type: 'error',
        trigger: 'blur',
      },],
        updateDate: [
      {
        required: true,
        message: '更新时间必填',
        type: 'error',
        trigger: 'blur',
      },],
        updateId: [
      {
        required: true,
        message: '修改人必填',
        type: 'error',
        trigger: 'blur',
      },],
  });
onMounted(() => {
});
const emit = defineEmits(['update:visibles', 'success']);

const handleOnConfirm = () => {
  form.value.validate().then((validateResult: any) => {
    if (validateResult === true) {
      submitLoading.value = true;
      doCreate({
        ...formData,
      }).then(() => {
        submitLoading.value = false;
        MessagePlugin.success('新增评分信息表成功');
        form.value.clearValidate();
        form.value.reset();
        handleClose();
        emit('success');
      });
    } else {
      MessagePlugin.error('表单验证失败');
    }
  });
};

const handleClose = () => {
  emit('update:visibles', false);
};
</script>
<style lang="less" scoped></style>
